package com.fj.spring.event.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JsonUtils {
    private static final Logger logger = LoggerFactory.getLogger(JsonUtils.class);
    private static ObjectMapper defaultMapper = new ObjectMapper();

    public JsonUtils() {
    }

    public static String toJson(Object value) {
        return toJson(defaultMapper, value);
    }

    public static String toJson(ObjectMapper mapper, Object value) {
        if (value == null) {
            return null;
        } else {
            ObjectMapper _mapper = mapper;
            if (mapper == null) {
                _mapper = defaultMapper;
            }

            try {
                return _mapper.writeValueAsString(value);
            } catch (JsonProcessingException var4) {
                logger.error("序列化错误: value=" + value, var4);
                return null;
            }
        }
    }

}
